/*
 * EntradaAtestadoMedico.java
 *
 * Created on December 20, 2007, 2:10 PM
 */

package erreAga.view.atestadoMedico;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import erreAga.dao.DaoException;
import erreAga.eb.AtestadoMedico;
import erreAga.service.ErreAgaService;
import erreAga.service.impl.ErreAgaServiceImpl;


/**
 *
 * @author  helder
 */
public class EntradaAtestadoMedico extends javax.swing.JFrame {

    /**
   *
   */
  private static final long serialVersionUID = 6519899532107389002L;

    /** Creates new form EntradaAtestadoMedico */
    public EntradaAtestadoMedico() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        labelFuncionario = new javax.swing.JLabel();
        labelMatricula = new javax.swing.JLabel();
        labelInicio = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        labelFim = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        labelMotivo = new javax.swing.JLabel();
        fieldFuncionario = new javax.swing.JTextField();
        fieldMatricula = new javax.swing.JTextField();
        fieldDataInicio = new javax.swing.JTextField();
        fieldDataFim = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaMotivo = new javax.swing.JTextArea();
        labelImagem = new javax.swing.JLabel();
        fieldImagem = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JSeparator();
        buttonCadastrar = new javax.swing.JButton();
        buttonCancelar = new javax.swing.JButton();
        buttonVerImg = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

   //     org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(telaspod.TelasPODApp.class).getContext().getResourceMap(EntradaAtestadoMedico.class);
        jLabel1.setText("Entrada de atestado médico"); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        labelFuncionario.setText("Funcionário:"); // NOI18N
        labelFuncionario.setName("labelFuncionario"); // NOI18N

        labelMatricula.setText("Matrícula:"); // NOI18N
        labelMatricula.setName("labelMatricula"); // NOI18N

        labelInicio.setText("Data Início:"); // NOI18N
        labelInicio.setName("labelInicio"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        labelFim.setText("Data Fim:"); // NOI18N
        labelFim.setName("labelFim"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        labelMotivo.setText("Motivo:"); // NOI18N
        labelMotivo.setName("labelMotivo"); // NOI18N

     //   fieldFuncionario.setText(resourceMap.getString("fieldFuncionario.text")); // NOI18N
        fieldFuncionario.setName("fieldFuncionario"); // NOI18N

     //   fieldMatricula.setText(resourceMap.getString("fieldMatricula.text")); // NOI18N
        fieldMatricula.setName("fieldMatricula"); // NOI18N

      //  fieldDataInicio.setText(resourceMap.getString("fieldDataInicio.text")); // NOI18N
        fieldDataInicio.setName("fieldDataInicio"); // NOI18N

      //  fieldDataFim.setText(resourceMap.getString("fieldDataFim.text")); // NOI18N
        fieldDataFim.setName("fieldDataFim"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        textAreaMotivo.setColumns(20);
        textAreaMotivo.setRows(5);
        textAreaMotivo.setName("textAreaMotivo"); // NOI18N
        jScrollPane1.setViewportView(textAreaMotivo);

        labelImagem.setText("Imagem:"); // NOI18N
        labelImagem.setName("labelImagem"); // NOI18N

//        fieldImagem.setText(resourceMap.getString("fieldImagem.text")); // NOI18N
        fieldImagem.setName("fieldImagem"); // NOI18N

        jSeparator4.setName("jSeparator4"); // NOI18N

        buttonCadastrar.setText("Cadastrar"); // NOI18N
        buttonCadastrar.setName("buttonCadastrar"); // NOI18N
        buttonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCadastrarActionPerformed(evt);
            }
        });

        buttonCancelar.setText("Cancelar"); // NOI18N
        buttonCancelar.setName("buttonCancelar"); // NOI18N
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });

        buttonVerImg.setText("Ver"); // NOI18N
        buttonVerImg.setName("buttonVerImg"); // NOI18N
        buttonVerImg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVerImgActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(labelMotivo)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                .addComponent(jLabel1)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(28, 28, 28)
                                    .addComponent(labelInicio)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(fieldDataInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(labelFim)
                                    .addGap(4, 4, 4)
                                    .addComponent(fieldDataFim, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(labelMatricula)
                                        .addComponent(labelFuncionario))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(fieldMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(fieldFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(labelImagem)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(fieldImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(buttonVerImg)))
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(buttonCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonCadastrar)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelFuncionario)
                    .addComponent(fieldFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMatricula))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelFim)
                    .addComponent(fieldDataInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fieldDataFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelInicio))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelImagem)
                    .addComponent(fieldImagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonVerImg))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMotivo))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonCadastrar)
                    .addComponent(buttonCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        // TODO add your handling code here:
      this.setVisible(false);
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void buttonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCadastrarActionPerformed
        // TODO add your handling code here:



      ErreAgaService erreAgaService = new ErreAgaServiceImpl();

      AtestadoMedico at = new AtestadoMedico();


      SimpleDateFormat formatador = new SimpleDateFormat("dd/mm/yy");


      try {
        at.setDataFim(formatador.parse(this.fieldDataFim.getText()));
        at.setDataInicio(formatador.parse(this.fieldDataInicio.getText()));
      } catch (ParseException e) {

        e.printStackTrace();
      }


      try {
        at.setFuncionario(erreAgaService.searchFuncionarioByNome(this.fieldFuncionario.getText()));
      } catch (DaoException e) {

        e.printStackTrace();
      }


      at.setCaminhoImagemAtestado(this.fieldImagem.getText());



      at.setMotivo(this.textAreaMotivo.getText());



      try {
        erreAgaService.saveAtestadoMedico(at);
      } catch (DaoException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }









    }//GEN-LAST:event_buttonCadastrarActionPerformed

    private void buttonVerImgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVerImgActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_buttonVerImgActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EntradaAtestadoMedico().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCadastrar;
    private javax.swing.JButton buttonCancelar;
    private javax.swing.JButton buttonVerImg;
    private javax.swing.JTextField fieldDataFim;
    private javax.swing.JTextField fieldDataInicio;
    private javax.swing.JTextField fieldFuncionario;
    private javax.swing.JTextField fieldImagem;
    private javax.swing.JTextField fieldMatricula;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel labelFim;
    private javax.swing.JLabel labelFuncionario;
    private javax.swing.JLabel labelImagem;
    private javax.swing.JLabel labelInicio;
    private javax.swing.JLabel labelMatricula;
    private javax.swing.JLabel labelMotivo;
    private javax.swing.JTextArea textAreaMotivo;
    // End of variables declaration//GEN-END:variables

}
